<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Hello React</title>
</head>
<body>

  <div id="root"></div>

  <script src="../lib/react.js"></script>
  <script src="../lib/react-dom.js"></script>
  <script src="../lib/babel.js"></script>
  
  <script type="text/babel">
    
    class App extends React.Component {
      
      constructor() {
        super()
        this.state = {
          counter: 0
        }
        this.increase = this.increase.bind(this)
        this.decrease = this.decrease.bind(this)
      }
      increase() {
        this.setState({
          counter: this.state.counter+1
        })
      }
      decrease() {
        this.setState({
          counter: this.state.counter-1
        })
      }

      render() {
        const { counter } = this.state
        return (
          <div>
            <div>当前数量:{counter}</div> 
            <button onClick={this.increase}>+1</button> 
            <button onClick={this.decrease}>-1</button> 
          </div>
        )
      }
    }

    // 将组件渲染到页面
    const root = ReactDOM.createRoot(document.querySelector("#root"))
    root.render(<App />)
  </script>
</body>
</html>